import java.util.ArrayList;
import java.util.List;

public class Generate {
    // leetcode 杨辉三角
    // https://leetcode.cn/problems/pascals-triangle/description/?envType=study-plan-v2&envId=top-100-liked
    public List<List<Integer>> generate(int numRows) {
        List<List<Integer>> ret = new ArrayList<>();
        List<Integer> firstRow = new ArrayList<>();
        firstRow.add(1);
        ret.add(firstRow);
        for (int i = 1; i < numRows; i++) {
            List<Integer> prevRow = ret.get(i-1);
            List<Integer> curRow = new ArrayList<>();
            curRow.add(1);
            for (int j = 1; j < i; j++) {
                curRow.add(prevRow.get(j-1) + prevRow.get(j));
            }
            curRow.add(1);
            ret.add(curRow);
        }
        return ret;
    }
}
